import config from '@/config/config.js';
import http from '@/api/http.js'

let processRequest={
    loadProcesses(process,page=1,limit=10,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/production/list?page="+page + "&limit=" + limit;
            if(process){
                if(process.processId){
                    url += "&processId=" + process.processId;
                }
                if(process.processName){
                    url += "&processName=" + process.processName;
                }
                if(process.processStatus){
                    url += "&processStatus=" + process.processStatus;
                }
            }
            console.log(url);
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    },addProcess(process,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/production/add";
            http.post(url,process,callBack);
        }else{
            callBack(undefined);
        }
    },countProcess(callBack){
        let token = localStorage.getItem("token");
        if(token){
            http.get(config.productionBaseUrl + "/production/count",callBack);
        }else{
            callBack(undefined);
        }
    },deleteProcess(processId,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/production/delete?processId="+processId;
            http.delete(url,callBack);
        }else{
            callBack(undefined);
        }
    },editProcess(process,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/production/edit";
            console.log("---------------------")
            console.log(process)
            http.post(url,process,callBack);
        }else{
            callBack(undefined);
        }
    },reDelete(processIds,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/production/reDelete?a=1";
            if(processIds){
                processIds.forEach(id=>url += '&processIds=' + id);
            }
            http.delete(url,callBack);
        }else{
            callBack(undefined);
        }
    },listAll(callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/production/listAll";
            console.log(url);
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    },showByProcessId(processId,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/production/showByProcess?processId=" + processId;
            console.log(url);
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    }
}

export default processRequest;